#!/bin/sh /etc/rc.common
# Copyright (C) 2017 lean <coolsnowwolf@gmail.com>

START=99

start()
{
	rfc=4096
	cc=$(grep -c processor /proc/cpuinfo)
	rsfe=$(echo $cc*$rfc | bc)
	sysctl -w net.core.rps_sock_flow_entries=$rsfe
	for fileRps in $(ls /sys/class/net/eth*/queues/rx-*/rps_cpus)
	do
		echo $cc > $fileRps
	done

	for fileRfc in $(ls /sys/class/net/eth*/queues/rx-*/rps_flow_cnt)
	do
		echo $rfc > $fileRfc
	done

	for fileRps in $(ls /sys/class/net/eth*/queues/tx-*/xps_cpus)
	do
		echo $cc > $fileRps
	done

	a=$(cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq)
	b=$(echo -n ' : ')
	c=$(cat /proc/cpuinfo | grep 'core id' | sort -u | wc -l)
	d=$(echo -n ' Core ')
	e=$(cat /proc/cpuinfo | grep 'processor' | wc -l)
	f=$(echo -n ' Thread ')
	g=${a}${b}${c}${d}${e}${f}

	mkdir -p /tmp/sysinfo
	echo $g > /tmp/sysinfo/model

	a=$(ip address | grep ^[0-9] | awk -F: '{print $2}' | sed "s/ //g" | grep '^[e]' | grep -v "@" | grep -v "\.")
	b=$(echo "$a" | wc -l)
	for i in $(seq 1 $b)
	do
		c=$(echo "$a" | sed -n ${i}p)
		ethtool -K $c rx-checksum on >/dev/null 2>&1
		ethtool -K $c tx-checksum-ip-generic on >/dev/null 2>&1 || (
		ethtool -K $c tx-checksum-ipv4 on >/dev/null 2>&1
		ethtool -K $c tx-checksum-ipv6 on >/dev/null 2>&1)
		ethtool -K $c tx-scatter-gather on >/dev/null 2>&1
		ethtool -K $c gso on >/dev/null 2>&1
		ethtool -K $c tso on >/dev/null 2>&1
		ethtool -K $c ufo on >/dev/null 2>&1
	done
}
